const { injectBabelPlugin } = require('react-app-rewired');
const rewireLess = require('react-app-rewire-less');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const definePlugin = function (config) {
  const plugin = new webpack.DefinePlugin({
    'process.env.PROFILE': JSON.stringify(process.env.PROFILE),
    'process.env.REACT_APP_FAVICON': JSON.stringify(process.env.REACT_APP_FAVICON || 'favicon.ico'),
  })
  // console.log(config.plugins);
  config.plugins.push(plugin);
  // console.log("-----------------------");
  // console.log(config.plugins);
  return config;
}

module.exports = function override(config, env) {
  // do stuff with the webpack config...
  // config = injectBabelPlugin(['import', { libraryName: 'antd', style: 'css' }], config);
  config = rewireLess(config, env);
  config = injectBabelPlugin(['import', { libraryName: 'antd', style: true }], config);

  config = definePlugin(config);

  /*config = rewireLess.withLoaderOptions({
    modifyVars: { "@primary-color": "#1DA57A" },
  })(config, env);*/

  return config;
};